﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Sudoku;

namespace SudokuTest
{
	class Program
	{
		static void Main(string[] args)
		{
			SudokuGame game = new SudokuGame();


			string easyGame00 =
				"29 5 1736" +
				"6     9 5" +
				" 3  79  2" +
				"8     694" +
				"  12     " +
				"4768    1" +
				"5   2 47 " +
				"    3  5 " +
				"3184     ";

			easyGame00 =
				"652   3 4" +
				"1893  572" +
				"4375 2   " +
				"3  7 8 59" +
				"   25  63" +
				" 15  3 4 " +
				" 41 359 7" +
				"    9 435" +
				"593 2    ";

			if (args.Length > 0)
				easyGame00 = args[0];

			game.Load(easyGame00);

			int assigned = -1;
			int left = game.Size * game.Size;
			while (assigned != 0 && left != 0)
			{
				assigned = 0;
				left = 0;
				for (int c = 0; c < game.Size; c++)
					for (int d = 0; d < game.Size; d++)
					{
						if (!game[c, d].IsSet)
						{
							List<int> values = SudokuGame.GetValueList(game.GetAvailableValues(c, d));
							if (values.Count == 1)
							{
								game[c, d].Value = (byte)values[0];
								assigned++;
							}
							else
							{
								left++;
							}
						}
					}
			}

			Console.WriteLine(game.ToString());
			Console.ReadKey(true);
		}
	}
}
